import 'package:flutter/cupertino.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:get/get.dart';
import 'package:get/get_connect/http/src/request/request.dart';
import 'package:xindong/common/xindong_api_path.dart';
import 'package:xindong/common/xindong_sezhi.dart';
import 'package:xindong/manager/network/xindong_networking.dart';
import 'package:xindong/manager/xindong_page_singleton.dart';
import 'package:xindong/manager/xindong_user_controller.dart';
import 'package:xindong/models/gift/xindong_gift_class.dart';
import 'package:xindong/res/assets_res.dart';
import 'package:xindong/utils/xindong_image_util.dart';
import 'package:xindong/widgets/gift/xindong_songli_controller.dart';
import 'package:xindong/widgets/gift/view/xindong_songli_sent_button.dart';

class XinDongSongLiToolBar extends StatelessWidget {
  const XinDongSongLiToolBar({super.key});

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 54,
      padding: const EdgeInsets.only(left: 15, right: 15, bottom: 10),
      child: Row(
        children: [
          GetBuilder<XinDongSongLiController>(builder: (controller) {
            // if (provider.generalTabController != null) {
            //   int currentIndex = provider.generalTabController!.index.round();
            //   // if (currentIndex == provider.mainTabController.length - 1 && provider.packageList.length > 0) {
            //   if (currentIndex == provider.generalTabController!.length - 1) {
            //     double total = 0;
            //     for (XinDongGiftClass model in provider.packageList) {
            //       total += (model.amount * (model.total ?? 1));
            //     }
            //     // 一键全刷
            //     return buildContainerOneKey(provider, total);
            //   }
            // }
            return buildContainerBalance();
          }),
          const Expanded(child: SizedBox()),
          const XinDongSongLiSentButton()
        ],
      ),
    );
  }

  /// 余额/充值
  Widget buildContainerBalance() {
    return GestureDetector(
      onTap: () => XinDongPageSingleton.instance.toRechargeYeMian(),
      behavior: HitTestBehavior.opaque,
      child: Row(
        children: [
          ImageUtil.asset(AssetsRes.ICON_GOLD_COIN, width: 22, height: 22),
          const SizedBox(width: 5),
          GetBuilder<XinDongUserController>(builder: (controller) {
            return Text(
              controller.balance,
              style: const TextStyle(fontSize: 16, fontWeight: FontWeight.normal, color: DZColors.titleColor),
            );
          }),
          const SizedBox(width: 16),
          const Text(
            "充值 >",
            style: TextStyle(fontSize: 14, fontWeight: FontWeight.w500, color: DZColors.mainColor, height: 1.2),
          ),
        ],
      ),
    );
  }

// /// 一键全刷
// Widget buildContainerOneKey(XinDongGiftSendProvider provider, double total) {
//   return GestureDetector(
//     onTap: () => provider.oneKeySend(),
//     behavior: HitTestBehavior.opaque,
//     child: Container(
//       alignment: Alignment.centerLeft,
//       child: Container(
//         alignment: Alignment.center,
//         margin: EdgeInsets.only(right: 10, top: 8, bottom: 8),
//         padding: EdgeInsets.only(left: 20, right: 20),
//         decoration: BoxDecoration(
//           border: new Border.all(color: DZColors.allGiftsSend, width: 1.0),
//           borderRadius: BorderRadius.circular(50),
//         ),
//         child: Column(
//           crossAxisAlignment: CrossAxisAlignment.center,
//           mainAxisAlignment: MainAxisAlignment.center,
//           children: [
//             Text(
//               "一键全刷",
//               style: TextStyle(fontSize: 11, color: DZColors.allGiftsSend),
//             ),
//             Text.rich(
//               TextSpan(text: "总价值：", children: [
//                 TextSpan(
//                   text: "${total.toStringAsFixed(2)}",
//                   style: TextStyle(fontSize: 8),
//                 )
//               ]),
//               style: TextStyle(fontSize: 7.5, color: DZColors.allGiftsSend, height: 1.2),
//             ),
//           ],
//         ),
//       ),
//     ),
//   );
// }
}
